package com.finley.flowabledemo.plc.controller;

import com.finley.flowabledemo.plc.data.PlcData;
import com.finley.flowabledemo.plc.service.S7SerializerService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/s7/serializer")
public class S7SerializerController {

    private final S7SerializerService serializerService;

    public S7SerializerController(S7SerializerService serializerService) {
        this.serializerService = serializerService;
    }

    /**
     * s7协议读取bean的值
     * @return
     */
    @GetMapping("/data")
    public PlcData readData() {
        return serializerService.read(PlcData.class);
    }


    /**
     * s7协议写入bean的值
     * @return
     */
    @PostMapping("/data")
    public void writeData(@RequestBody PlcData data) {
        serializerService.write(data);
    }
}